const mongoose=require('mongoose');
const moment=require('moment');

const AppSchema = new mongoose.Schema({
    name:{
        type:String,
        required:true
    },
    url:{//首页地址
        type:String,
        required:true
    },
    desc:{//应用描述
        type:String,
        required:true
    },
    callback:{//验证回调地址
        type:String,
        required:true
    },
    creator:{//应用创建者
        type:mongoose.Schema.ObjectId,
        ref:'User'
    },
    client_id:{//hash
        type:String,
        required:true
    },
    secret:{//hash
        type:String,
        require:true
    },
    time:{
        type:Date,
        required:true
    },
    users:[//使用此应用的用户（资源拥有者）
        {
            type:mongoose.Schema.ObjectId,
            ref:'User'
        }
    ]
});

AppSchema.virtual('timeStr').get(function (){
    return moment(this.time).format('YYYY-MM-DD HH:mm:ss');
});

module.exports=mongoose.model('App',AppSchema);